import { HYEventStore } from "hy-event-store"
import { getRanking } from "../service/api_music"

export const rankingMap = {
  0: "newRanking",
  1: "hotRanking",
  2: "originRanking",
  3: "upRanking"
}

export const rankingStore = new HYEventStore({
  state: {
    newRanking: {}, // 0新歌
    hotRanking: {}, // 1热歌
    originRanking: {}, // 2原创
    upRanking: {} // 3飙升
  },
  actions: {
    getRankingDataAction(ctx) {
      // 0: 新歌榜 1：热歌榜 2：原创榜 3：飙升榜
      for(let i = 0; i < 4; i++) {
        getRanking(i).then(res => {
          const rankingName = rankingMap[i]
          ctx[rankingName] = res.playlist
        })
      }
    }
  }
})